package com.example.myshopping3.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充处理器
 */
@Component
public class FillDateHandler implements MetaObjectHandler {
    /**
     * 当插入数据时自动调用
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", ()->new Date(), Date.class);
    }

    /**
     * 修改数据时自动调佣该方法
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", ()->new Date(), Date.class);
    }
}
